package cn.itcast.mr.invertedIndex;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class InvertedIndexCombiner extends Reducer<Text, Text, Text, Text> {
	private static Text info = new Text();
	public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
		// process values
		int sum = 0;
		for (Text val : values) {
			sum += Integer.parseInt(val.toString());
		}
		int splitIndex = key.toString().indexOf(":");
		info.set(key.toString().substring(splitIndex+1)+":"+sum);
		key.set(key.toString().substring(0,splitIndex));
		context.write(key, info);
	}
}
